﻿using AutoMapper;
using Lanbt.Core.Entity.Dto;
using Lanbt.Core.Entity.Dto.lanbt_power;
using Lanbt.Core.Entity.Dto.lanbt_user;
using Lanbt.Core.Entity.EntityDB;
using Lanbt.Core.Utility.Extent;
using Lanbt.Core.Utility.Helper;

namespace Lanbt.Core.Service
{
    public class ModelProfile: Profile
    {

        public ModelProfile()
        {

            #region lanbt_user

            CreateMap<InsertUserInput, lanbt_user>()
                .ForMember(dot => dot.Password, q => q.MapFrom(s => EncryptHelper.MD5Encrypt(s.Password)));

            CreateMap<UpdateUserInput, lanbt_user>();

            CreateMap<lanbt_user, GetCurrentUserOutput>()
                .ForMember(dto=>dto.RoleIds,x=>x.Ignore());

            CreateMap<lanbt_user, QueryUsersOutput>();

            CreateMap<lanbt_user, GetUserInfo>();

            #endregion

            #region lanbt_role

            CreateMap<lanbt_role, XM_SelectOutput>()
                .ForMember(dto => dto.name, opt => opt.MapFrom(d => d.Name))
                .ForMember(dto => dto.value, opt => opt.MapFrom(d => d.ID));

            #endregion

            #region lanbt_power

            CreateMap<InsertPowerInput, lanbt_power>();

            CreateMap<lanbt_power, QueryPagedPowerListOutput>()
                .ForMember(dto => dto.PowerTypeName, opt => opt.MapFrom(x => x.PowerType.Description()));

            CreateMap<UpdatePowerInput, lanbt_power>();

            #endregion

        }
    }
}
